// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.kit.conversationkit.ui.normal.viewholder;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.netease.yunxin.kit.common.ui.utils.AvatarColor;
import com.netease.yunxin.kit.conversationkit.ui.R;
import com.netease.yunxin.kit.conversationkit.ui.bean.ExtDataBean;
import com.netease.yunxin.kit.conversationkit.ui.databinding.ConversationViewHolderBinding;
import com.netease.yunxin.kit.conversationkit.ui.model.ConversationBean;

public class ConversationP2PViewHolder extends ConversationBaseViewHolder {
  public ConversationP2PViewHolder(@NonNull ConversationViewHolderBinding binding) {
    super(binding);
  }

  @Override
  public void onBindData(ConversationBean data, int position) {
    super.onBindData(data, position);
    String name = data.infoData.getName();
    viewBinding.avatarView.setData(
        data.infoData.getAvatar(),
       data.infoData.getAvatarName(),
        AvatarColor.avatarColor(data.infoData.getContactId()));
    viewBinding.nameTv.setText(name);
//    Log.e("网易云信会话列表的Item", "该用户没有扩展信息getExtensionMap: "+data.infoData.getUserInfo().getExtension());
    if (!TextUtils.isEmpty(data.infoData.getUserInfo().getExtension())){
      String json=data.infoData.getUserInfo().getExtension();
      ExtDataBean bean =new Gson().fromJson(json,ExtDataBean.class);
      if (bean!=null){
        if (bean.getIfzhaoshang()!=0){
          viewBinding.imgTag.setVisibility(View.VISIBLE);
          if(bean.getLevel()==0){
            viewBinding.imgTag.setImageResource(R.drawable.attract0);
          }else if(bean.getLevel()==1) {
            viewBinding.imgTag.setImageResource(R.drawable.attract1);
          }else if(bean.getLevel()==2) {
            viewBinding.imgTag.setImageResource(R.drawable.attract2);
          }
          //等级
          viewBinding.tvAgent.setVisibility(View.VISIBLE);
          viewBinding.tvAgent.setText(bean.getArea()+"服务中心");
        }

      }
    }else{
      viewBinding.levelBg.setVisibility(View.GONE);
      viewBinding.imgTag.setVisibility(View.GONE);
      viewBinding.tvAgent.setVisibility(View.GONE);
    }

  }
}
